package com.milhouz.quizzdroid.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;

import com.milhouz.quizzdroid.R;
import com.milhouz.quizzdroid.bean.Game;
import com.milhouz.quizzdroid.view.PlayerResultAdapter;

public class GamePauseDialog extends Dialog {

	ListView mPlayersResults;

	private final PlayerResultAdapter mAdapter;

	public GamePauseDialog(final Activity activity, final Game game) {
		super(activity, R.style.Dialog);
		setContentView(R.layout.game_pause);
		setCancelable(true);

		// blur effect on the background
		WindowManager.LayoutParams lp = getWindow().getAttributes();
		lp.dimAmount = 0.0f;
		getWindow().setAttributes(lp);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

		// set up image view
		mAdapter = new PlayerResultAdapter(this.getContext(), R.layout.player_result, game.getPlayersArray());
		mPlayersResults = (ListView) findViewById(R.id.summaryGame);
		mPlayersResults.setAdapter(this.mAdapter);

		// set up button
		Button quitButton = (Button) findViewById(R.id.quitGameBtn);
		quitButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				cancel();
				activity.finish();
			}
		});

		// set up button
		Button resumeButton = (Button) findViewById(R.id.resumeGameBtn);
		resumeButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				cancel();
			}
		});
	}

	public void showPauseDialog(final Game game) {
		this.mAdapter.updateItems(game.getPlayersArray());
		super.show();
	}
}
